const app = getApp();
const publicFun = require('/utils/public.js');
import { getClimateActionDetail, setClimateActionSubmit, getClimateActionUserDay } from '/utils/request'

let index = 0,
  items = [],
  flag = true,
  itemId = 1;

Page({
  data: {
    itemList: [],
    correspondList: [],
    detailsInput: '',
    submitMask: false, // 默认 false
    maskType: 1, // 弹窗类型 提示：1 else 其它（成功失败）
    submitType: 1, // 1 成功 else 其它（失败）
    // exampleMask: false, // 图片示例弹窗, 默认false
    
    btnDisabled: true,
    wmHeight: 140, // 182 动态设置canvas高度
    isFirstDay: null,
    submitCounts: 0,
    pixelRatio: 2
  },
  onLoad(options) {
    items = []; // 清空水印数组
    this.setData({ 
      itemList: [],
      actionid: options.actionid,
      sysData: app.globalData.systemInfo
    })
    this.getClimateActionDetail(this.data.actionid);
  },
  onShow() {
    let that = this;
    my.getStorage({
      key: 'byoimgurl',
      success: (res) => {
        let url = res.data;
        if(url){
          that.setData({
            selectImg: url, 
            byoImgUrl: url, //判断自带杯标题文案
            btnDisabled : false
          })
          setTimeout(()=> {
            that.getImgWH(url); //获取图片的等比宽高比
          }, 1000)
        }
      },
    });
  },
  onHide() {
    my.removeStorage({
      key: 'byoimgurl',
    });
  },
  getFirstDayDay() {// 获取是否首日提交
    this.getClimateActionUserFirstDay(); 
  },
  async getClimateActionUserFirstDay() {
    try{
      var params = {
        userid: app.globalData.userid
      }
      const res = await getClimateActionUserDay(params)
      if(res.S == 1){
        let state = false; // 是否打开弹窗
        let type = 1; // 提交接口传工具类型参数 
        if(res.IsFirst == 1){ // 1=是首日 0=非首日
          state = true;
          type = 2; // 1相机 2相机、相册 
          res.ZhuYi = '注意：'+res.ZhuYi;
        }else{
          this.chooseSSImg();
        }
        this.setData({
          submitMask: state,
          maskContentJson: res,
          isdingwei: type
        })
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败');
      }
    }catch(e){
      publicFun.showToast('失败，请稍后再试')
    }
  },
  chooseSSImg() {
    let sourceType = ['camera']
    if(this.data.isdingwei == 2){
      sourceType.push('album');
    }
    my.chooseImage({
      chooseImage: 1,
      sourceType: sourceType,
      count: 1,
      sizeType: 'compressed',
      success: (ress) => {
        my.compressImage({
          apFilePaths: ress.apFilePaths,
          compressLevel: 1,
          success: res => {
            let url = res.apFilePaths[0];
            this.setData({ selectImg: url })
            this.getImgWH(url); //获取图片的等比宽高比

            this.setData({btnDisabled : false}) 
          }
        })
      }
    })
  },
  
  byoJump() {
    my.navigateTo({
      url: '/pages/byoSurvey/byoSurvey'
    })
  },
  getContentInput(e) { //获取框里的内容
    this.setData({
      detailsInput: e.detail.value
    })
  },
  closeTipsMask() {
    if(this.data.submitCounts == 1){
      my.redirectTo({
        url: '/pages/rankList/rankList'
      })
    }else{
      if(this.data.maskContentJson.IsFirst == 1){ // 首次
        this.chooseSSImg();
        this.setData({ submitMask: false });
      }
    }
  },
  closeSubmitMask() {
    if(this.data.submitType == 1){
      my.redirectTo({
        url: '/pages/rankList/rankList'
      })
    }
    this.setData({ submitMask: false, btnDisabled: false });
  },
  closeMask() {
    this.setData({ submitMask: false, btnDisabled: false });
  },
  exampleTap() {
    my.previewImage ({
      current: 0,
      urls: this.data.detailJson.Img,
    })
  },

  getImgWH(imgSrc) {
    let that = this;
    let sysData = that.data.sysData;
    let query = my.createSelectorQuery()
    query.select('.file_img .bigImg').boundingClientRect();
    query.exec((ress) => {
      let resData = ress[0];
      let boxW = resData.width-6;

      sysData.windowWidth = sysData.windowWidth - (sysData.windowWidth - boxW); // 容器的宽度
      sysData.windowHeight = sysData.windowHeight - (sysData.windowHeight - boxW); // 容器的宽度 暂时无用

      my.getImageInfo({
        src: imgSrc,
        success: (res) => {
          that.setData({
            sysData: sysData,
            imgWidth: sysData.windowWidth, // 容器里的图片宽
            imgHeight: (res.height / res.width) * sysData.windowWidth, // 图片高/图片宽*容器宽
            // imgHeight: (sysData.windowWidth * res.height) / res.width,
            currentWidth: res.width, // 图片原始宽度 无用
            currentHeight: res.height, // 图片原始高度 无用
            // pixelRatio: sysData.pixelRatio // 像素比率
          })
          this.getWaterMark(this.data.canvasImg);  
        }
      })
    });
  },
  getWaterMark(url) {
    let data = {}
    my.getImageInfo({
      src: url,
      success: res => {
        // 初始化数据
        data.width = res.width/2; //宽度
        data.height = res.height/2; //高度
        data.image = url; //地址
        data.id = ++itemId; //id
        data.top = this.data.imgHeight/2 - res.height/4; //top定位 
        data.left = this.data.imgWidth/2 - res.width/4; //left定位
        //圆心坐标
        // data.x = data.left + data.width / 4;
        // data.y = data.top + data.height / 4;
        data.scale = 1; //scale缩放
        data.oScale = 1; //方向缩放
        data.rotate = 1; //旋转角度
        data.active = false; //选中状态
        items[0] = data;
        this.setData({
          itemList: items
        })
      }
    })
  },
  deleteItem(e) { // 删除水印
    let newList = [];
    for (let i = 0; i < items.length; i++) {
      if (e.currentTarget.dataset.id != items[i].id) {
        newList.push(items[i])
      }
    }
    if (newList.length > 0) {
      newList[newList.length - 1].active = true; // 剩下图片组最后一个选中
    }
    items = newList;
    this.setData({
      itemList: items
    })
  },

  // 合成图片
  synthesisImg() {
    let that = this;
    let data = that.data;
    my.createSelectorQuery().select('#compositeCanvas').node().exec((res) => {
      const canvas = res[0].node;
      const ctx = canvas.getContext('2d');
      // console.log('图片原始宽高:', data.currentWidth, data.currentHeight)
      // console.log('容器宽高',data.imgWidth, data.imgHeight)

      // canvas.width = data.currentWidth;
      // canvas.height = data.currentHeight; //  * data.pixelRatio
      my.showLoading();
      // 图片
      const img = canvas.createImage();
      img.src = data.selectImg;
      img.onload = () => {
        canvas.width = data.imgWidth * data.pixelRatio;
        canvas.height = data.imgHeight * data.pixelRatio;
        // console.log('canvas*分辨率后宽高', canvas.width, canvas.height)

        ctx.scale(data.pixelRatio, data.pixelRatio);
        ctx.drawImage(img, 0, 0, data.imgWidth, data.imgHeight);
        // 水印
        let wmItme = items[0];
        if(wmItme){
          const wmImg = canvas.createImage();
          wmImg.src = wmItme.image;
          wmImg.onload = () => {
            ctx.scale(wmItme.scale, wmItme.scale);  
            ctx.rotate(0);
            ctx.translate(wmItme.left, wmItme.top);
            ctx.drawImage(wmImg, 0, 0, wmItme.width, wmItme.height);

            setTimeout(() => {
              canvas.toTempFilePath({
                x: 0,
                y: 0,
                width: data.imgWidth * data.pixelRatio,
                height: data.imgHeight * data.pixelRatio,
                destWidth: data.imgWidth * data.pixelRatio, // * data.pixelRatio
                destHeight: data.imgHeight * data.pixelRatio,
                fileType: 'jpg',
                success: (res) => {
                  // console.log('合并水印成功', data.imgWidth * data.pixelRatio, data.imgHeight * data.pixelRatio)
                  that.setData({uploadImg: res.tempFilePath, btnDisabled: true});
                  that.sendClimateActionImg(res.tempFilePath);
                },
                fail: (e) => {
                  // console.log('水印合成：', e)
                  publicFun.showToast('失败，请稍后再试')
                  that.setData({btnDisabled: false});
                }
              })
            }, 500)
          }
          wmImg.onerror = () => {
            publicFun.showToast('失败，请稍后再试')
          }
        }else{
          canvas.toTempFilePath({
            x: 0,
            y: 0,
            width: data.imgWidth * data.pixelRatio,
            height: data.imgHeight * data.pixelRatio,
            destWidth: data.imgWidth * data.pixelRatio,
            destHeight: data.imgHeight * data.pixelRatio,
            fileType: 'jpg',
            success: (res) => {
              that.setData({uploadImg: res.tempFilePath, btnDisabled: true});
              that.sendClimateActionImg(res.tempFilePath);
            },
            fail: (e) => {
              publicFun.showToast('失败，请稍后再试')
              that.setData({btnDisabled: false});
            }
          })
        }
      }
      img.onerror = (e) => {
        // console.log('水印图片：', e)
        publicFun.showToast('失败，请稍后再试');
      }
    })
  },
  sendClimateActionImg(imgUrl) {
    let uploads = [publicFun.commonUpLoadImg(publicFun.api.commonImg, imgUrl, {})];
    Promise.all(uploads).then(res => {
      let data = res[0];
      if(data.S == 1){
        this.sendClimateActionBtn(data.rpath, data.width, data.height);
      }else{
        my.hideLoading();
        publicFun.showToast(data.M ? data.M : '加载失败')
      }
    }).catch(() => {
      my.hideLoading();
      publicFun.showToast('失败，请稍后再试')
    });
  },
  async sendClimateActionBtn(fmurl, fmurlWidth, fmurlHeight) {
    try{
      let thisData = this.data;
      let location = app.globalData.location;
      let aqi = app.globalData.aqiObj;

      var params = {
        userid: app.globalData.userid,
        dt: publicFun.getTimestamp(),
        describe: thisData.detailJson.Info1, // 默认描述
        describe1: thisData.detailsInput, // 用户填写的 支付宝小程序请搜索：气候行动小程序
        address: location.address, //地址
        lat: location.lat, //纬度
        lng: location.lng, //经度
        province: location.province, //省
        city: location.city, //市
        area: location.district, //区
        airlevel: aqi ? aqi.A.L : 0, //空气质量级别
        huancun: app.globalData.hc, //缓存名称（ShareList_V4_1返回的Key）
        aqi: aqi ? aqi.A.A : 0, //Aqi值
        temperature: aqi ? aqi.W.T : 0, //实况温度
        weatherdes: aqi ? aqi.W.M : '', //实况天气（例如：晴，多云 等）
        fmurl: fmurl, //封面
        fmurl_width: fmurlWidth, //封面宽
        fmurl_height: fmurlHeight, //封面高
        actionid: thisData.actionid, //气候行动id
        actionxishu: thisData.detailJson.XiShu, //气候行动系数
        isdingwei: thisData.isdingwei, // 拍摄工具
      }
      const res = await setClimateActionSubmit(params)
      my.hideLoading();
      if(res.S == 1){
        let contentJson = {};
        let maskType = 2;
        if(res.IsTip == 1){
          contentJson.Msg = '您今日提交“'+this.data.detailJson.Name+'”行动已达上限3次，试试去打卡其他气候行动吧！';
          contentJson.ZhuYi = '（小贴士：当日同一种气候行动打卡3次以后再提交的记录不纳入“气候行动榜单统计”，自带杯随手拍调查不受限制。）';
          maskType = 1;
        }
        this.setData({ 
          submitMask: true, 
          maskContentJson: contentJson,
          maskType: maskType,
          submitType: 1,
          submitCounts: res.IsTip
        })
        my.removeStorage({
          key: 'byoimgurl'
        });
      }else{
        this.setData({ submitMask: true, submitType: 0 })
      }
    }catch(e){
      my.hideLoading();
      publicFun.showToast('失败，请稍后再试')
    }
  },
  async getClimateActionDetail(actionid) { 
    try{
      var params = {
        actionid: actionid,
        version: 1,
        userid: app.globalData.userid,
      }
      const res = await getClimateActionDetail(params)
      if(res.S == 1){
        this.setData({ 
          detailJson: res,
          correspondList: res.L
        });
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败');
      }
    }catch(e){
      publicFun.showToast('失败，请稍后再试')
    }
  },

  // 水印
  onCanvasWMReady() {
    const that = this;
    my.createSelectorQuery().select('#canvas').node().exec((res) => {
      const canvas = res[0].node;
      const ctx = canvas.getContext('2d');
      that.canvasWM = canvas;
      that.ctxWM = ctx;
      setTimeout(() => {
        that.waterMaskCanvas2D();
      }, 1000)
    })
  },
  waterMaskCanvas2D() {
    const that = this;
    const canvas = this.canvasWM;
    const ctx = this.ctxWM;
    
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.font = 'bold 22px DIN';
    // ctx.textAlign = "center";
    let text1 = this.data.detailJson.Name;
    let yellowTextWidth = this.getStrWidth(ctx, text1)+92; // 92 两个引号
    let textArr = this.gettTextLength(ctx, text1, 220); // 文字数组 文字宽度：200
    let boxWidth = 0; // 容器宽度

    textArr.length > 1 ? boxWidth = 310 : boxWidth = yellowTextWidth; // 超过两行容器宽度：310
    this.setData({ wmHeight: this.data.wmHeight+(textArr.length*32) })

    // 黄框
    ctx.save(); // 保存当前绘图上下文。
    this.roundRect(ctx, 40, 102, boxWidth+12, 36+(textArr.length*32), 12, '#ffffff'); // 78
    ctx.beginPath()
    ctx.strokeStyle = '#000000';
    ctx.lineWidth = 4; //线宽
    ctx.roundRect(46, 108, boxWidth, 24+(textArr.length*32), [12]); // 66
    ctx.stroke(); 
    
    this.roundRect(ctx, 48, 110, boxWidth-4, 20+(textArr.length*32), 12, '#FFDC0C'); // 62
    ctx.restore(); // 恢复之前保存的绘图上下文。

    const imgLeft = canvas.createImage()
    imgLeft.src = require('/images/canvas/icon_left.png')
    imgLeft.onload = () => {
      ctx.drawImage(imgLeft, 58, 129, 24, 20)
    }

      // 文字位置
    if(textArr.length > 1){ // 超过两行
      let tY = 0;
      for (let b = 0; b < textArr.length; b++) {
        if(b == 0){
          tY = 100 + (b + 1) * 48;
        }else if( b == 1) {
          tY = 100 + (b + 1) * 38
        }else if(b == 2){
          tY = 100 + (b + 1) * 34
        }else if(b == 3){
          tY = 100 + (b + 1) * 30
        }
        ctx.fillText(textArr[b], 92, tY);
      }
    }else{ // 一行
      ctx.fillText(text1, 92, 146);
      // ctx.strokeText(text1, 92, 146);
    }

    const imgRight = canvas.createImage()
    imgRight.src = require('/images/canvas/icon_right.png');
    imgRight.onload = () => {
      let yHeight = 129;
      if(textArr.length == 2){ // 超过两行
        yHeight= 129+28;
      }else if(textArr.length == 3){
        yHeight= 129+28*2;
      }
      ctx.drawImage(imgRight, boxWidth+10, yHeight, 24, 20)
    }

    // 上半部分-strart
    ctx.font = 'bold 42px DIN';
    let lineArr = [15]; // 边框距x轴
    let jiantantImg = [60, 34]; // 长、宽
    let unitImg = [22, 26]; 
    let text = this.data.detailJson.XiShu; //+this.data.detailJson.XiShuUnit;
    let greenTextWidth = this.getStrWidth(ctx, text)+jiantantImg[0]+unitImg[0]+90;
    // 白框
    this.roundRect(ctx, 0, 35, greenTextWidth+12, 80, 12, '#ffffff');
    
    // 黑框
    ctx.beginPath()
    ctx.strokeStyle = '#000000';
    ctx.lineWidth = 4; //线宽
    ctx.roundRect(6, 41, greenTextWidth, 68, [12]);
    ctx.stroke();
    // 绿框
    this.roundRect(ctx, 8, 43, greenTextWidth-4, 64, 12, '#90FF00');
    // 绿框内容
    const imgArrow = canvas.createImage();
    imgArrow.src = require('/images/canvas/icon_leftArrow.png');
    imgArrow.onload = () => {
        ctx.drawImage(imgArrow, lineArr[0], 50, 44, 8)
    }

    const imgReduct = canvas.createImage(); // 减碳文字背景
    imgReduct.src = require('/images/canvas/icon_carbon.png');
    imgReduct.onload = () => {
        ctx.drawImage(imgReduct, lineArr[0], 64, jiantantImg[0], jiantantImg[1])
    }

    ctx.fillText(text, lineArr[0]+62, 97);

    const imgUnit = canvas.createImage(); // 单位文字背景
    imgUnit.src = require('/images/canvas/icon_unit.png');
    imgUnit.onload = () => {
      let xWidth = lineArr[0]+jiantantImg[0]+this.getStrWidth(ctx, text)+5;// 间距:3
      ctx.drawImage(imgUnit, xWidth, 72, unitImg[0], unitImg[1])
    }

    const imgTree = canvas.createImage()
    imgTree.src = require('/images/canvas/icon_tree.png');
    imgTree.onload = () => {
      ctx.drawImage(imgTree, greenTextWidth-34*2, 0, 94, 92)
    }

    if (textArr.length > 1){
      var totalWidth = boxWidth+55;
    }else{
      if(greenTextWidth > yellowTextWidth){
        var totalWidth = greenTextWidth+55;
      }else{
        var totalWidth = yellowTextWidth+55;
      }
    }

    setTimeout(() => {
      canvas.toTempFilePath({
        x: 0,
        y: 0,
        width: totalWidth,
        height: this.data.wmHeight,
        // destWidth: boxWidth+98,
        // destHeight: this.data.wmHeight,
        success(res) {
          that.setData({canvasImg: res.tempFilePath})
        },
      })
    }, 500)
  },
  getStrWidth(ctx, str) {
    var lineWidth = 0
    for (let code of str) {
      lineWidth += ctx.measureText(code).width
    }
    return lineWidth
  },
  gettTextLength(ctx, t, w) { // 几行文字
    let chr = t.split("")
    let temp = ""
    let row = []

    for (let a = 0; a < chr.length; a++) {
      if (ctx.measureText(temp).width < w && ctx.measureText(temp + (chr[a])).width <= w) {
        temp += chr[a];
      } else {
        row.push(temp);
        temp = chr[a];
      }
    }
    row.push(temp)
    return row;
  },
  roundRect (ctx, x, y, w, h, r, config) {
    let color = 'transparent'
    if (typeof config === 'string') {
      color = config
    }
    ctx.save()
    // 开始绘制
    ctx.beginPath()
    // 因为边缘描边存在锯齿，最好指定使用 transparent 填充
    if (config.type) {
      if (config.type === 'fill') {
        ctx.fillStyle = config.fillColor || 'transparent';
      } else if (config.type === 'stroke') {
        ctx.fillStyle = config.strokeColor || 'transparent';
      } else if (config.type === 'both') {
        ctx.fillStyle = config.fillColor || 'transparent';
        ctx.setStrokeStyle(config.strokeColor || 'transparent')
      }
    } else {
      ctx.fillStyle = color;
      ctx.strokeStyle = '#000000';
    }
    if (!config.round || config.round.leftTop) {
      // 绘制左上角圆弧
      ctx.arc(x + r, y + r, r, Math.PI, Math.PI * 1.5)
      // 绘制border-top
      ctx.moveTo(x + r, y)
    } else {
      // 绘制border-top
      ctx.moveTo(x, y + r)
      ctx.lineTo(x, y)
      ctx.lineTo(x + r, y)
    }
    ctx.lineTo(x + w - r, y)
    if (!config.round || config.round.rightTop) {
      // 绘制右上角圆弧
      ctx.arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2)
    } else {
      ctx.lineTo(x + w - r, y)
      ctx.lineTo(x + w, y)
      ctx.lineTo(x + w, y + r)
    }
    // 绘制border-right
    ctx.lineTo(x + w, y + h - r)
    if (!config.round || config.round.rightBottom) {
      // 绘制右下角圆弧
      ctx.arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5)
    } else {
      ctx.lineTo(x + w, y + h - r)
      ctx.lineTo(x + w, y + h)
      ctx.lineTo(x + w - r, y + h)
    }
    // 绘制border-bottom
    ctx.lineTo(x + r, y + h)
    if (!config.round || config.round.leftBottom) {
      // 绘制左下角圆弧
      ctx.arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI)
    } else {
      ctx.lineTo(x + r, y + h)
      ctx.lineTo(x, y + h)
      ctx.lineTo(x, y + h - r)
    }
    // 绘制border-left
    ctx.lineTo(x, y + r)

    if (config.type) {
      if (config.type === 'fill') {
        ctx.fill()
      } else if (config.type === 'stroke') {
        ctx.stroke()
      } else if (config.type === 'both') {
        ctx.stroke()
        ctx.fill()
      }
    } else {
      ctx.fill()
    }

    ctx.closePath()
    // 剪切
    ctx.clip()
    ctx.restore()
  },

  WraptouchStart(e) {
    items[index].active = true;
    this.setData({
      itemList: items
    })
  },
  WraptouchMove(e) {
    let data = e.detail;
    items[index].left = data.x;
    items[index].top = data.y;
    this.setData({
      itemList: items
    })
  },

  // 放大缩小
  oTouchStart(e) {
    //找到点击的那个图片对象，并记录
    for (let i = 0; i < items.length; i++) {
      items[i].active = false;
      if (e.currentTarget.dataset.id == items[i].id) {
        index = i;
        items[index].active = true;
      }
    }
    //获取作为移动前角度的坐标
    items[index].tx = e.touches[0].clientX;
    items[index].ty = e.touches[0].clientY;
    //移动前的角度
    items[index].anglePre = this.countDeg(items[index].x, items[index].y, items[index].tx, items[index].ty)
    //获取图片半径
    items[index].r = this.getDistancs(items[index].x, items[index].y, items[index].left, items[index].top);
  },
  oTouchMove(e) {
    if (flag) {
      flag = false;
      setTimeout(() => {
        flag = true;
      }, 100)
    }
    //记录移动后的位置
    items[index]._tx = e.touches[0].clientX;
    items[index]._ty = e.touches[0].clientY;
    //移动的点到圆心的距离
    items[index].disPtoO = this.getDistancs(items[index].x, items[index].y, items[index]._tx, items[index]._ty - 10)

    items[index].scale = items[index].disPtoO / items[index].r;
    items[index].oScale = 1 / items[index].scale;

    //移动后位置的角度
    items[index].angleNext = this.countDeg(items[index].x, items[index].y, items[index]._tx, items[index]._ty)
    //角度差
    //items[index].new_rotate = items[index].angleNext - items[index].anglePre;

    //叠加的角度差
    //items[index].rotate += items[index].new_rotate;
    //items[index].angle = items[index].rotate; //赋值

    //用过移动后的坐标赋值为移动前坐标
    items[index].tx = e.touches[0].clientX;
    items[index].ty = e.touches[0].clientY;
    items[index].anglePre = this.countDeg(items[index].x, items[index].y, items[index].tx, items[index].ty)

    //赋值setData渲染
    this.setData({
      itemList: items
    })

  },
  getDistancs(cx, cy, pointer_x, pointer_y) {
    var ox = pointer_x - cx;
    var oy = pointer_y - cy;
    return Math.sqrt(
      ox * ox + oy * oy
    );
  },
  /* *参数1和2为图片圆心坐标 *参数3和4为手点击的坐标 *返回值为手点击的坐标到圆心的角度 */
  countDeg(cx, cy, pointer_x, pointer_y) {
    var ox = pointer_x - cx;
    var oy = pointer_y - cy;
    var to = Math.abs(ox / oy);
    var angle = Math.atan(to) / (2 * Math.PI) * 360;
    if (ox < 0 && oy < 0) //相对在左上角，第四象限，js中坐标系是从左上角开始的，这里的象限是正常坐标系  
    {
      angle = -angle;
    } else if (ox <= 0 && oy >= 0) //左下角,3象限  
    {
      angle = -(180 - angle)
    } else if (ox > 0 && oy < 0) //右上角，1象限  
    {
      angle = angle;
    } else if (ox > 0 && oy > 0) //右下角，2象限  
    {
      angle = 180 - angle;
    }
    return angle;
  },
});
